package main

import (
	"fmt"
	"learn/basic"
	"sync"
)

var wg sync.WaitGroup

func main() {
	//数组
	//basic.Array()
	//切片
	//basic.Slice()
	//Map
	//basic.Map()
	//Func
	//basic.Func()
	//basic.Point()
	basic.Struct()
	//basic.Reflect()
	//basic.GetConfigIni()
	//basic.Goroutine()
	//basic.Channel()
	//a := "1234"
	//getType(a)
	//a := make([]int, 2)
	//a[0] = 1
	//a[1] = 2
	//b := append(a, 3)
	//fmt.Print(a, b)
	//ch := make(chan struct{}, 1)
	//ch1 := make(chan struct{}, 1)
	//ch2 := make(chan struct{}, 1)
	//ch2 <- struct{}{}
	//for i := 0; i < 100; i++ {
	//	wg.Add(3)
	//	go func() {
	//		go cat(ch, ch2)
	//		go dog(ch, ch1)
	//		go fish(ch1, ch2)
	//	}()
	//}
	//wg.Wait()
}

func cat(ch chan<- struct{}, ch2 <-chan struct{}) {
	fmt.Print("cat start")
	_, ok := <-ch2
	if ok {
		fmt.Println("cat")
		ch <- struct{}{}
		wg.Done()
	}
}

func dog(ch <-chan struct{}, ch1 chan<- struct{}) {
	fmt.Print("dog start")
	_, ok := <-ch
	if ok {
		fmt.Println("dog")
		ch1 <- struct{}{}
		wg.Done()
	}
}

func fish(ch1 <-chan struct{}, ch2 chan<- struct{}) {
	fmt.Print("fish start")
	_, ok := <-ch1
	if ok {
		fmt.Println("fish")
		ch2 <- struct{}{}
		wg.Done()
	}
}

func getType(a interface{}) {
	value, ok := a.(string)
	fmt.Print(value, ok)
	//switch a.(type) {
	//case string:
	//	fmt.Print(112)
	//default:
	//	fmt.Print(12321)
	//}
}
